{layout name="Layout/layout" /}
<link href="/bootstrap/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title">
                    <h5>独立借款人车贷列表</h5>
                    <div class="ibox-tools">
                        <!--<a href="{:url('Borrower/borrowCreate')}" class="btn btn-primary">新增标的</a>-->
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <form action="" method="get">
                           <div class="row">
                                <div class="col-sm-3 m-b-xs">
                                    <div class="row">
                                        <div class="col-sm-3 m-b-xs">批次号：</div>
                                        <div class="col-sm-6 m-b-xs">
                                            <input type="input" name="num"  {if condition="isset($num)"} value="{$num}"  {/if}  class="form-control input-s-sm inline" value="">
                                        </div>
                                    </div>
                                </div>
                               <div class="col-sm-3 m-b-xs">
                                   <div class="row">
                                       <div class="col-sm-3 m-b-xs">姓名：</div>
                                       <div class="col-sm-6 m-b-xs">
                                           <input type="input" name="user_name"
                                                  {if condition="isset($user_name)"} value="{$user_name}"  {/if}
                                           class="form-control input-s-sm inline">
                                       </div>
                                   </div>
                               </div>
                               <div class="col-sm-3 m-b-xs">
                                   <div class="row">
                                       <div class="col-sm-3 m-b-xs">证件号：</div>
                                       <div class="col-sm-6 m-b-xs">
                                           <input type="input" name="idcard"
                                                  {if condition="isset($idcard)"} value="{$idcard}"  {/if}
                                           class="form-control input-s-sm inline">
                                       </div>
                                   </div>
                               </div>
                               <div class="col-sm-3 m-b-xs">
                                   <div class="row">
                                       <div class="col-sm-3 m-b-xs">手机号：</div>
                                       <div class="col-sm-6 m-b-xs">
                                           <input type="input" name="mobile"
                                                  {if condition="isset($mobile)"} value="{$mobile}"  {/if}
                                           class="form-control input-s-sm inline">
                                       </div>
                                   </div>
                               </div>
                                <div class="col-sm-3 m-b-xs">
                                    <div class="row">
                                        <div class="col-sm-4 m-b-xs">审核状态：</div>
                                        <div class="col-sm-6 m-b-xs">
                                            <select name="status" class="form-control input-s-sm inline">
                                                {volist name="map_status" id="vo"}
                                                <option value="{$key}" {if condition="isset($status) && $status ==$key "} selected {/if}>{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>
                                </div>
                               <div class="col-sm-4 m-b-xs">
                                   <div class="row">
                                       <div class="col-sm-2 m-b-xs">导入时间：</div>
                                       <div class="col-sm-4 m-b-xs">
                                           <input {if condition="isset($start_time) "} value="{$start_time}"  {/if} name="start_time" id="start" placeholder="开始日期"  class="form-control datepicker" readonly >
                                       </div>
                                       <div class="col-sm-1 m-b-xs">--</div>
                                       <div class="col-sm-4 m-b-xs">
                                           <input {if condition="isset($end_time) "} value="{$end_time}" {/if}  type="input" id="end" name="end_time"  placeholder="结束日期"  id="end"  readonly class="form-control input-s-sm inline datepicker" ></div>
                                   </div>
                               </div>
                               <div class="col-sm-1 m-b-xs">
                                   <button  class="btn btn-primary" > 搜索</button>
                               </div>
                           </div>
                        </form>
                    </div>
                </div>

                <div class="project-list">
                        <table class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th></th>
                                <th>批次号</th>
                                <th>姓名</th>
                                <th>手机号</th>
                                <th>身份证号</th>
                                <th>借款金额 </th>
                                <th>借款期限（天） </th>
                                <th>还款方式</th>
                                <th>审核状态</th>
                                <th>创建时间 </th>
                                <th>更新时间</th>
                                <th>状态</th>
                                <th>操作 </th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.bq_id}</td>
                                <td>{$vo.batch_number}</td>
                                <td>{$vo.real_name}</td>
                                <td>{$vo.user_phone}</td>
                                <td>{$vo.idcard}</td>
                                <td>{$vo.money} </td>
                                <td>{$vo.duration} </td>
                                <td>{if condition="isset($repayment_type_map[$vo.repayment_type])"}
                                    {$repayment_type_map[$vo.repayment_type]}
                                    {else/}异常错误{/if}</td>
                                <td>{$status_map[$vo.status]}</td>
                                <td>{$vo.create_time} </td>
                                <td>
                                    {if condition="strtotime($vo.update_time) eq '0'"}
                                        --{else /}
                                        {$vo.update_time}
                                    {/if}
                                </td>
                                <td>
                                    {if condition="$vo.idcard eq ''" }
                                    <a val="{$vo.uid}" href="javascript:void(0)" class="real-name">去实名</a>
                                    {/if}
                                    {if condition="$vo.is_set_pay_password eq 0" }
                                    <a href="javascript:void(0)" val="{$vo.uid}" class="sina-paypasswd"> | 设置支付密码</a>
                                    {/if}
                                    {if  condition="$vo.status eq 1" }
                                    审核通过
                                    {/if}
                                </td>
                                <td>
                                    {if condition=" $vo.status !=1" }<!--1为审核通过-->
                                    <a href="/merchant/borrower/editBorrowDetail?id={$vo.bq_id}" val="{$vo.uid}" class="btn btn-primary btn-sm ">编辑</a>
                                    <button class="btn btn-danger btn-sm delete" onclick="delect({$vo.bq_id})">删除</button>
                                    <button class="btn btn-sm" onclick="reviewrq({$vo.bq_id}, {$vo.uid})">审核通过</button>
                                    {/if}

                                    <a href="/merchant/borrower/getPersonBorrowDetail?id={$vo.bq_id}"  class="btn btn-warning btn-sm ">详情</a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                            <tfoot>
                            </tfoot>
                        </table>
                        <div class="row">{$pageElem}</div>
                    </div>

            </div>
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog"  aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">实名认证</h4>
                <small id="real-name-result" class="font-bold text-danger"></small>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>真实姓名</label>
                    <input type="text" id="real-name"
                           placeholder="请输入真实姓名"
                           class="form-control">
                </div>
                <div class="form-group">
                    <label>身份证</label>
                    <input type="text" id="idcard"
                           placeholder="请输入真实身份证号码"
                           class="form-control">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="save-realname">保存</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/bootstrap/date/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/bootstrap/date/bootstrap-datetimepicker.zh-CN.js"></script>
<link rel="stylesheet" href="/bootstrap/date/bootstrap-datetimepicker.min.css">
<!-- Sweet alert -->
<script src="/bootstrap/js/plugins/sweetalert/sweetalert.min.js"></script>
<script>
    $(document).ready(function(){
        $("#loading-example-btn").click(function(){
              history.go(0);
              //  btn=$(this);simpleLoad(btn,true);simpleLoad(btn,false)})});function simpleLoad(btn,state){if(state){btn.children().addClass("fa-spin");btn.contents().last().replaceWith(" Loading")}else{setTimeout(function(){btn.children().removeClass("fa-spin");btn.contents().last().replaceWith(" Refresh")},2000)}
        });
        var real_name_uid;

        $(".real-name").click(function(){
            real_name_uid= $(this).attr("val");
            $('#myModal6').modal('show');
        });


        $('#save-realname').click(function () {

            var realname = $("#real-name").val();
            var idcard = $("#idcard").val();

            if (realname == null || realname ==""){
                $('#real-name-result').html("请输入真实姓名");
            }
            if (idcard == null || idcard ==""){
                $('#real-name-result').html("请输入真实身份证");
            }
            $('#real-name-result').html("");
            console.log("ddddd");

            $.ajax({
                type:'post',
                url:"/merchant/Borrower/realnameAjax",
                data:{uid:real_name_uid,realname:realname, idcard:idcard},
                success: function(data){
                    data = eval(data);
                    if(data.code!=0) {
                        $('#real-name-result').html(data.message);
                        return
                    }else {
                        $('#myModal6').modal('hide');
                    }
                }
            });
        });

        $('#myModal6').on('hidden.bs.modal', function () {
            $('#real-name-result').html();
            var realname = $("#real-name").val('');
            var idcard = $("#idcard").val('');
        });
        //设置支付密码
        $('.sina-paypasswd').click(function () {
            var user_id = $(this).attr("val");
            var url = window.location.href;
            $.ajax({
                type:'post',
                url:"/merchant/User/setSinaPasswdAjax",
                data:{uid:user_id,return_url:url},
                success: function(data){
                    data = eval(data);
                    if(data.code!=0) {
                        alert(data.msg);
                        return
                    }
                    if(data.data.redirect_url!==undefined){
                        window.location.href = data.data.redirect_url;
                    }else{
                        alert(data.msg);
                    }
                  //  window.open(data.data.redirect_url, "设置支付密码");
                }
            });
        });

    });
        //日期选择
    (function($){
        $.fn.datetimepicker.dates['zh-CN'] = {
            days: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
            daysShort: ['周日','周一','周二','周三','周四','周五','周六'],
            daysMin: ['日','一','二','三','四','五','六'],
            months: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
            monthsShort: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
            today: '今天',
            suffix: [],
            meridiem: [],
            weekStart: 1,
            format: 'yyyy-mm-dd'
        };
    }(jQuery));
    $(function() {
        //初始化日期插件
        $("#start").datetimepicker({
            language : 'zh-CN',
            weekStart : 1,
            todayBtn : 1,
            autoclose : 1,
            todayHighlight : 1,
            startView : 2,
            minView: "month",
            format: 'yyyy-mm-dd',
            forceParse : 0,
            endDate : new Date()
        }).on('hide', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var startTime = event.date;
            $('#end').datetimepicker('setStartDate',startTime);
            $('#end').val("");
        });
        $("#end").datetimepicker({
            language : 'zh-CN',
            weekStart : 1,
            todayBtn : 1,
            autoclose : 1,
            todayHighlight : 1,
            startView : 2,
            minView: "month",
            format: 'yyyy-mm-dd',
            forceParse : 0,
            endDate : new Date()
        }).on('hide', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var endTime = event.date;
            $('#start').datetimepicker('setEndDate',endTime);
        });
    });

    function  delect(id) {
        swal({
            title: "您确定要删除这条信息吗",
            text: "删除后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type:'post',
                url:"/merchant/Borrower/deleteOne",
                data:{id:id},
                success: function(data){
                    data = eval(data);
                    if(data.code!=0) {
                        swal("已取消", data.message, "error");
                        return
                    }else {
                        swal("删除成功！", "您已经永久删除了这条信息。", "success");
                        window.location.reload();
                    }
                }
            });
           /* */
        });

    }

    function  reviewrq(rqid,borrower_uid) {
        swal({
            title: "您确定要审核通过这条信息吗",
            text: "审核通过后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "通过",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type:'post',
                url:"/merchant/Borrower/reviewBorrowRequest",
                data:{borrow_uid:borrower_uid, borrow_bqid:rqid},
                success: function(data){
                    data = eval(data);
                    if(data.code!=0) {
                        swal("已取消", data.message, "error");
                        return
                    }else {
                        swal("审核成功！", "您已经审核通过了这条信息。", "success");
                        window.location.reload();
                    }
                }
            });
            /* */
        });

    }

</script>
